define(function(require, exports, module) {

  var log = require('log');
  var chaxun = require('chaxun');
  
  function makeWord($list){
  //给单词加回调
    $list.find(":not(iframe)").andSelf().contents().filter(function() {
        return this.nodeType == 3;
    }).each(function(){
      text = this.nodeValue.replace(/([\w'-]+)/g,"<span class='word'>$1</span>");          
      $(this).replaceWith(text);
    });    
  }
  var count = 5;
  var postindex = 1;
  exports.addpage = function addpage( pageindex,complete ){    
    var url= "http://m.fmylife.com/?page="+pageindex;    
    $.ajax({
        url:url,
        success:function(data) {
          log("load success " );
          var $html = $(data);
          
          var fmlstr = "";
          $html.find("p.text").each(function() {
              fmlstr = fmlstr + "<p class='item'>"+postindex+". "+$(this).html()+"</p>";
              postindex=postindex+1;
          });
          var $fml = complete(fmlstr);
          makeWord($fml);
        },
        error:function(){
          log('fml load error '+count);
          count=count-1;
          if(count>0){
            addpage();
          }else{
            complete(null);
          }
        }
    });
  };
});